package com.awenhui.demo.core.base;

/**
 * 控制器基类
 * 
 * @author yuxf
 */
public class BaseController {

    /**
     * 成功
     *
     * @return
     */
    public ActionResult<?> success() {
        ActionResult<String> actionResult = new ActionResult<>();
        actionResult.setSuccess(true);
        actionResult.setCode(ResultCode.SUCCESS.getValue());
        actionResult.setMessage(ResultCode.SUCCESS.getDescription());
        actionResult.setData(null);
        return actionResult;
    }

    /**
     * 成功
     * 
     * @param data
     * @return
     */
    public <T> ActionResult<T> success(T data) {
        ActionResult<T> actionResult = new ActionResult<>();
        actionResult.setSuccess(true);
        actionResult.setCode(ResultCode.SUCCESS.getValue());
        actionResult.setMessage(ResultCode.SUCCESS.getDescription());
        actionResult.setData(data);
        return actionResult;
    }

    /**
     * 错误
     * 
     * @param resultCode
     * @return
     */
    public ActionResult<?> error(IBaseEnum resultCode) {
        ActionResult<Object> actionResult = new ActionResult<>();
        actionResult.setSuccess(false);
        actionResult.setCode(ResultCode.SUCCESS.getValue());
        actionResult.setMessage(ResultCode.SUCCESS.getDescription());
        actionResult.setData(null);
        return actionResult;
    }

    /**
     * 错误
     * 
     * @param message
     * @return
     */
    public ActionResult<?> error(String message) {
        ActionResult<Object> actionResult = new ActionResult<>();
        actionResult.setSuccess(false);
        actionResult.setCode(ResultCode.SUCCESS.getValue());
        actionResult.setMessage(message);
        actionResult.setData(null);
        return actionResult;
    }

    /**
     * 错误
     * 
     * @param message
     * @return
     */
    public ActionResult<?> error(int code, String message) {
        ActionResult<Object> actionResult = new ActionResult<>();
        actionResult.setSuccess(false);
        actionResult.setCode(code);
        actionResult.setMessage(message);
        actionResult.setData(null);
        return actionResult;
    }

    /**
     * 错误
     * 
     * @param message
     * @param code
     * @param data
     * @return
     */
    public ActionResult<?> error(int code, String message, Object data) {
        ActionResult<Object> actionResult = new ActionResult<>();
        actionResult.setSuccess(false);
        actionResult.setCode(code);
        actionResult.setMessage(message);
        actionResult.setData(data);
        return actionResult;
    }

}